#ifndef VECTOR2_H
#define VECTOR2_H

namespace Cvekas {

/// 2D Vector
struct Vector2 : public D3DXVECTOR2 
{
public:
	Vector2();
    Vector2(const float* f);
    Vector2(const D3DXFLOAT16* f);
    Vector2(float x, float y);
    Vector2(const D3DXVECTOR2& v);

    operator D3DXVECTOR2&();
    operator const D3DXVECTOR2&() const;

    void set(float vx, float vy);
    float length() const;
    float lengthSq() const;
    float dot(const Vector2& v) const;
    void normalize();
	void rotate(float angle);
    Vector2 getNormalized() const;
	Vector2 getRotated(float angle) const;
};


inline Vector2::Vector2() 
	: 
D3DXVECTOR2() 
{}

inline Vector2::Vector2(const float *f) 
	: 
D3DXVECTOR2(f)
{}

inline Vector2::Vector2(const D3DXFLOAT16 *f) 
	: 
D3DXVECTOR2(f) 
{}

inline Vector2::Vector2(float vx, float vy) 
	: 
D3DXVECTOR2(vx, vy) 
{}

inline Vector2::Vector2(const D3DXVECTOR2& v) 
	: 
D3DXVECTOR2(v) 
{}

inline void Vector2::set(float vx, float vy) 
{ 
	x=vx; 
	y=vy; 
}

inline float Vector2::length() const { return D3DXVec2Length(this); };

inline float Vector2::lengthSq() const { return D3DXVec2LengthSq(this); };

inline float Vector2::dot( const Vector2& v ) const { return D3DXVec2Dot(this,&v); }

inline void Vector2::normalize() 
{
   D3DXVec2Normalize( this, this );
}

inline void Vector2::rotate(float angle)
{
	*this = this->getRotated(angle);
}

inline Vector2 Vector2::getNormalized() const 
{
   Vector2 v;
   D3DXVec2Normalize( &v, this );
   return v;
}

inline Vector2 Vector2::getRotated(float angle) const
{
	Vector2 v;
	float sin_a = sin(angle);
	float cos_a = cos(angle);
	v.x = cos_a * x - sin_a * y;
	v.y = sin_a * x + cos_a * y;
	return v;
}

inline Vector2::operator D3DXVECTOR2&() 
{ 
	return *this; 
}

inline Vector2::operator const D3DXVECTOR2&() const 
{ 
	return *this;
}

} // namespace

#endif